import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToMany,
  JoinTable,
} from 'typeorm';
import { Role } from './role.entity';
@Entity({
  name: 'users',
})
export class User {
  @PrimaryGeneratedColumn()
  id: number;
  @Column({
    length: 20,
    comment: '用户名',
  })
  username: string;

  @Column({
    length: 200,
    comment: '密码',
    select: false, // 默认查询时不返回该字段
  })
  password: string;

  @Column({
    length: 100,
    comment: '密码盐',
    select: false,
  })
  salt: string;

  @Column({
    length: 20,
    comment: '昵称',
  })
  nickname: string;

  @Column({
    length: 50,
    comment: '邮箱',
  })
  email: string;

  @Column({
    length: 200,
    comment: '头像',
    default:
      'https://i0.hdslb.com/bfs/face/af239f7145ebe7fa0cdfe52b0742bd0916e86b08.jpg@240w_240h_1c_1s_!web-avatar-nav.avif',
  })
  avatar: string;

  @Column({
    length: 20,
    comment: '手机号',
  })
  phone: string;

  @Column({
    comment: '是否冻结',
    default: false,
  })
  isFrozen: boolean;

  @Column({
    comment: '是否管理员',
    default: false,
  })
  isAdmin: boolean;

  @CreateDateColumn({
    comment: '创建时间',
  })
  createdAt: Date;

  @UpdateDateColumn({
    comment: '更新时间',
  })
  updatedAt: Date;

  @ManyToMany(() => Role)
  @JoinTable({
    name: 'user_roles',
  })
  roles: Role[];
}
